<template>
  <div>
    <el-form :inline="true" :model="searchData" class="demo-form-inline">
      <el-form-item :label="item.title" v-for="(item, index) in searchType" :key="index">
        <div v-if="item.type == 1">
          <el-input v-model="searchData[item.model]" :placeholder="item.hint" />
        </div>
        <div v-if="item.type == 2">
          <el-date-picker v-model="searchData[item.model]" type="date" :placeholder="item.hint" />
        </div>
        <div v-if="item.type == 3">
          <el-select v-model="searchData[item.model]" :placeholder="item.hint" class="selectBox">
            <el-option
              v-for="item in item.options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
      </el-form-item>
      <el-form-item>
        <div>
          <el-button type="primary" @click="getSearchData(0)">搜索</el-button>
          <el-button type="primary" @click="getSearchData(1)">重置</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, reactive, defineProps, defineEmits } from 'vue'

let searchData = reactive({})
let allProps = defineProps(['searchType'])
let emit = defineEmits(['getSearchData'])
let searchType = allProps.searchType
const getSearchData = (data) => {
  if (data == 1) {
    const keys = Object.keys(searchData)
    let obj = {}
    keys.forEach((item) => {
      obj[item] = ""
    })
    Object.assign(searchData, obj)
  }
  emit('getSearchData', searchData)
}
defineExpose(getSearchData)
</script>

<style lang="scss" scoped>
.selectBox {
  width: 200px;
}
</style>